﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using GSLMS.Core;

namespace GSLMS.WebAPP
{
    [AttributeUsage(AttributeTargets.All, AllowMultiple = false, Inherited = true)]
    public class AdminAttribute : ActionFilterAttribute
    {

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (filterContext.HttpContext.Session["CurentUser"] == null)
            {
                if (string.IsNullOrEmpty(filterContext.HttpContext.Request["_"]))
                {
                    filterContext.Result = new RedirectResult("login");
                }
                else
                {
                    filterContext.HttpContext.Response.Clear();
                    filterContext.HttpContext.Response.Write("{" + string.Format(HelperCommon.AJAXFORMAT, 301, ResourceManager.SessionOver, "", "Login", "forward") + "}");
                    filterContext.HttpContext.Response.End();
                }
            }
        }
    }
}
